package com.longxi.tianjintianbao.ui.adapter.multitype.completeEnter;

import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.completeEnter.PicturesChoose;
import com.longxi.tianjintianbao.ui.adapter.FullyGridLayoutManager;
import com.longxi.tianjintianbao.ui.adapter.GridImageAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.List;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class PicturesChooseViewBinder extends ItemViewBinder<PicturesChoose, PicturesChooseViewBinder.ViewHolder> {

    BaseActivity mContext;
    List<LocalMedia> selectList;
    private GridImageAdapter adapter;
    public PicturesChooseViewBinder(BaseActivity mContext, List<LocalMedia> selectList, GridImageAdapter adapter) {
        this.mContext = mContext;
        this.selectList = selectList;
        this.adapter = adapter;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.include_image_picker, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull PicturesChoose picturesChoose) {
        adapter.setList(selectList);
        adapter.setSelectMax(2);
        holder.mRecyclerView.setAdapter(adapter);

        FullyGridLayoutManager manager = new FullyGridLayoutManager(mContext, 4, GridLayoutManager.VERTICAL, false);
        holder.mRecyclerView.setLayoutManager(manager);

//        holder.mEtContent.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//                enterEditText.setValue(holder.mEtContent.getText().toString());
//                listener.onSuccess(enterEditText);
//            }
//
//            @Override
//            public void afterTextChanged(Editable editable) {
//
//            }
//        });

    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        RecyclerView mRecyclerView;
        ViewHolder(View itemView) {
            super(itemView);
            mRecyclerView = itemView.findViewById(R.id.recyclerView);
        }
    }

}
